package com.ruoyi.business.modbus.domain;

/**
 * Modbus RTU主站设备配置对象
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
public class ModbusRtuMasterDevice extends ModbusMasterDevice
{
    private static final long serialVersionUID = 1L;

    /** 串口名称 */
    private String serialPort;

    /** 波特率 */
    private Integer baudRate;

    /** 数据位 */
    private Integer dataBits;

    /** 停止位 */
    private Integer stopBits;

    /** 校验位 */
    private String parity;

    public ModbusRtuMasterDevice() {
        super();
    }

    public ModbusRtuMasterDevice(String deviceSN, String deviceName, 
                          String serialPort, Integer baudRate, Integer timeout, Integer retries) {
        super(deviceSN, deviceName, timeout, retries);
        this.serialPort = serialPort;
        this.baudRate = baudRate;
        this.dataBits = 8;
        this.stopBits = 1;
        this.parity = "NONE";
    }

    public ModbusRtuMasterDevice(String deviceSN, String deviceName, 
                          String serialPort, Integer baudRate, Integer dataBits, 
                          Integer stopBits, String parity, Integer timeout, Integer retries) {
        super(deviceSN, deviceName, timeout, retries);
        this.serialPort = serialPort;
        this.baudRate = baudRate;
        this.dataBits = dataBits;
        this.stopBits = stopBits;
        this.parity = parity;
    }

    /**
     * 创建RTU主站设备的静态工厂方法
     */
    public static ModbusRtuMasterDevice create(String deviceSN, String deviceName, 
                                        String serialPort, Integer baudRate) {
        return new ModbusRtuMasterDevice(deviceSN, deviceName, serialPort, baudRate, 3000, 3);
    }

    @Override
    public String getDeviceType() {
        return "RTU";
    }

    // Getters and Setters
    public String getSerialPort() {
        return serialPort;
    }

    public void setSerialPort(String serialPort) {
        this.serialPort = serialPort;
    }

    public Integer getBaudRate() {
        return baudRate;
    }

    public void setBaudRate(Integer baudRate) {
        this.baudRate = baudRate;
    }

    public Integer getDataBits() {
        return dataBits;
    }

    public void setDataBits(Integer dataBits) {
        this.dataBits = dataBits;
    }

    public Integer getStopBits() {
        return stopBits;
    }

    public void setStopBits(Integer stopBits) {
        this.stopBits = stopBits;
    }

    public String getParity() {
        return parity;
    }

    public void setParity(String parity) {
        this.parity = parity;
    }

    @Override
    public String toString() {
        return "ModbusRtuMasterDevice{" +
                "deviceSN='" + getDeviceSN() + '\'' +
                ", deviceName='" + getDeviceName() + '\'' +
                ", deviceType='" + getDeviceType() + '\'' +
                ", serialPort='" + serialPort + '\'' +
                ", baudRate=" + baudRate +
                ", dataBits=" + dataBits +
                ", stopBits=" + stopBits +
                ", parity='" + parity + '\'' +
                ", timeout=" + getTimeout() +
                ", retries=" + getRetries() +
                '}';
    }
}